<?php
/**
 * Each engineer has a duty to keep the code elegant
 * Created by wolffy.
 * Author @wolffy<13750088090@sina.cn>
 * Date: 2018/8/14
 * Time: 17:39
 */
namespace App\Http\Controllers\Api\V2_0_0;

use App\Http\Requests\Api\V2_0_0\DistributCreateGroupRequest;
use App\Http\Requests\Api\V2_0_0\DistributRequest;
use App\Http\Requests\Api\V2_0_0\PersonalAccountWithdrawRequest;
use App\Services\DistributService;
use App\Services\PersonalAccountWithdrawService;
use App\Services\UserProfitService;
use Illuminate\Http\Request;

class DistributController extends BaseController
{
    protected $userProfitService;
    protected $personalAccountWithdrawService;
    protected $distributService;

    public function __construct(UserProfitService $userProfitService,
                                PersonalAccountWithdrawService $personalAccountWithdrawService,
                                DistributService $distributService)
    {
        parent::__construct();
        $this->userProfitService = $userProfitService;
        $this->personalAccountWithdrawService = $personalAccountWithdrawService;
        $this->distributService = $distributService;
    }

    /**
     * 获取团队成员
     */
    public function getGroupMember()
    {
        return $this->distributService->getGroupMember($this->user['user_id']);
    }

    /**
     * 获取收益统计
     */
    public function getProfit(DistributRequest $request)
    {
        return $this->distributService->distributProfit($this->user['user_id'], $request->date_format,
            $request->date_format_type, $request->group_member_id,
            $request->start_date . ' 00:00:00', $request->end_date . ' 23:59:59');
    }

    /**
     * 创建团队
     */
    public function createGroup(DistributCreateGroupRequest $request)
    {
        return $this->distributService->createGroup($this->user, $request->group_name,
            $request->group_mobile, $request->profit_percent);
    }

    /**
     * 团队数量
     */
    public function groupCount()
    {
        return $this->distributService->groupCount($this->user['user_id']);
    }
}